<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <!-- html与java的交互需要现在头部引入ajax -->
    <script type="text/javascript" src="../../scripts/jquery-1.10.2.min.js"></script>

    <style type="text/css">
        body {
            width: 99%;
        }
    </style>
</head>
<body>
<h3>测试本地数据读取</h3>
<hr/>
<div class="table_respository">
    <table class="table_data">
        <thead>
        <tr>
            <th>#</th>
            <th>书籍名称&nbsp;&nbsp;&nbsp;&nbsp;</th>
            <th>作者&nbsp;&nbsp;&nbsp;&nbsp;</th>
            <th>出版时间&nbsp;&nbsp;&nbsp;&nbsp;</th>
            <th>评&nbsp;&nbsp;&nbsp;&nbsp;级</th>
            <th>操&nbsp;&nbsp;&nbsp;&nbsp;作</th>
        </tr>
        </thead>
    <#list model as item>
        <tr align="center">
            <td align="center">${item_index}</td>
            <td align="center">${item.bookname}</td>
            <td align="center">${item.author}</td>
            <td align="center">${item.publishTime}</td>
            <td align="center">${item.grade}</td>
            <td>
                <button type="button" onclick="deleteBookById(${item.id})">
                    删除
                </button>
            </td>
            <td>
                <button type="button" onclick="addOne()">
                    添加
                </button>
            </td>
        </tr>
    </#list>
    </table>
    <hr>
    <form action="/books/add">
        名称：&nbsp<input name="bookname" type="text" id="et_name"/><br>
        作者：&nbsp<input name="author" type="text" id="et_author"/><br>
        时间：&nbsp<input name="publishTime" type="date" id="et_time"/><br>
        评级：&nbsp<input name="grade" type="number" id="et_grade"/><br>
        <input type="submit" value="保存">
    </form>
</div>
<script>
    function deleteBookById(id) {
        $.ajax({
            url: '/books/delete',
            data: {bookId: id},
            success: function (data) {
                if (data == 1) {
                    alert("删除成功！")
                    window.location.reload();
                } else {
                    alert("删除失败");

                }
            }
        });
    }


</script>
</body>
</html>
